package cn.fl.audit.controller;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.*;
import cn.fl.audit.condition.AudCreditInfoQueryCondition;
import cn.fl.audit.service.IAudCreditInfoService;
import cn.fl.audit.service.IAudReturnVisitService;
import cn.fl.audit.service.IAudStandingBookService;
import cn.fl.audit.vo.AudCarInfoVO;
import cn.fl.audit.vo.AudCreditInfoVO;
import cn.fl.audit.vo.AudStandingBookVO;
import cn.fl.carloan.vo.OdrPrdBscInfoVO;
import cn.fl.commons.result.ResponseData;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.preloan.IAuditCreditInfoService;
import cn.fl.preloan.IAuditStandingBookService;
import cn.fl.preloan.IProjectMapRiskService;
import cn.fl.preloan.condition.AuditCreditInfoQueryCondition;
import cn.fl.preloan.condition.AuditStandingBookQueryCondition;
import cn.fl.preloan.constants.AuditConstans;
import cn.fl.preloan.dto.audit.*;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.service.IPrjMapRiskService;
import cn.fl.project.service.IPrjPrdBscInfoService;
import cn.fl.project.vo.PrjMapRiskVO;
import cn.fl.project.vo.PrjPrdBscInfoVO;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import net.sf.json.JSONArray;
import org.omg.CORBA.Current;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @Description: 信审整体资料 控制层
 */
@Controller
@RequestMapping("/audit/audCreditInfo")
public class AudCreditInfoController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(AudCreditInfoController.class);

	/**
	 * AudCreditInfo 服务层BEAN
	 */
	@Autowired
	private IAudCreditInfoService audCreditInfoService;
	@Autowired
	private IAudReturnVisitService audReturnVisitService;

	@Autowired
	private IPrjPrdBscInfoService prjPrdBscInfoService;

    @Autowired
    private IPrjMapRiskService prjMapRiskService;

    @Autowired
	private IAuditCreditInfoService auditCreditInfoService;

    @Autowired
	private IProjectMapRiskService projectMapRiskService;

    @Autowired
	private IAuditStandingBookService auditStandingBookService;
	

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("audit/audCreditInfo/list");
		BaseLogUtils.info(logger, "toListPage", "跳转到列表页面.", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 到新增/修改页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String projectId = request.getParameter("projectId");//项目ID
		String proIntId = request.getParameter("proIntId");//流程实例ID
		String taskId = request.getParameter("taskId");//任务ID
		String taskDefKey = request.getParameter("taskDefKey");//任务KEY
		ModelAndView view = new ModelAndView("audit/audCreditInfo/audCreditInfoAdd");
		view.addObject("id", id);
		view.addObject("projectId", projectId);
		view.addObject("proIntId", proIntId);
		view.addObject("taskId", taskId);
		view.addObject("taskDefKey", taskDefKey);
		BaseLogUtils.info(logger, "toModifyPage", "跳转到新增/修改页面.[id="+id+",projectId="+projectId+",proIntId="+proIntId+"]", CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 到动态字段组件页面-车辆运营
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toPrdOperateDynamicFldPage.do", method = { RequestMethod.GET,RequestMethod.POST })
	public ModelAndView toDynamicBizPage(HttpServletRequest request, HttpServletResponse response) {
		String bizTypCd = request.getParameter("bizTypCd");
		String bizCd = request.getParameter("bizCd");
		ModelAndView view = new ModelAndView("audit/audCreditInfo/audCreditInfoAddPrdOperateDynamicPage");
		if(StringUtils.isNotEmpty(bizTypCd) && StringUtils.isNotEmpty(bizCd)){
			view.addObject("bizTypCd", bizTypCd);
			view.addObject("bizCd", bizCd);
		}else{
			view.addObject("bizTypCd", "");
			view.addObject("bizCd", "");
		}
		return view;
	}
	
	/**
	 * 到动态字段组件页面-车辆信息
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toPrdInfoDynamicFldPage.do", method = { RequestMethod.GET,RequestMethod.POST })
	public ModelAndView toDynamicBizPageForPrdInfo(HttpServletRequest request, HttpServletResponse response) {
		String bizTypCd = request.getParameter("bizTypCd");
		String bizCd = request.getParameter("bizCd");
		ModelAndView view = new ModelAndView("audit/audCreditInfo/audCreditInfoAddPrdInfoDynamicPage");
		if(StringUtils.isNotEmpty(bizTypCd) && StringUtils.isNotEmpty(bizCd)){
			view.addObject("bizTypCd", bizTypCd);
			view.addObject("bizCd", bizCd);
		}else{
			view.addObject("bizTypCd", "");
			view.addObject("bizCd", "");
		}
		return view;
	}
	
	/**
	 * 获取货物种类下拉数据
	 */
	@RequestMapping(value = "/getGoodsTypJSON.do", method = { RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public Object getGoodsTypJSON(HttpServletRequest request, HttpServletResponse response){
		String lvl = request.getParameter("lvl");
		String PCode = request.getParameter("PCode");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		BaseLogUtils.info(logger, "getGoodsTypJSON", "获取货物种类,请求参数.[lvl="+lvl+",PCode="+PCode+"]", CurrentThreadContext.getCurrentUserName());
		if(StringUtils.isEmpty(lvl) && StringUtils.isEmpty(PCode)){
			return result;
		}
		List<KeyValueVO> goodsTypList = new ArrayList<KeyValueVO>();
		try{
			if(StringUtils.isNotEmpty(lvl)){
				goodsTypList = this.audCreditInfoService.searchGoodsTypListByLvl(lvl);
			}else if(StringUtils.isNotEmpty(PCode)){
				goodsTypList = this.audCreditInfoService.searchGoodsTypListByPCode(PCode);
			}
			if(CollectionUtils.isNotEmpty(goodsTypList)){
				result.setData(JSONObject.toJSON(goodsTypList));
			}
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "获取失败.[lvl="+lvl+",PCode="+PCode+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getById", "获取失败.[lvl="+lvl+",PCode="+PCode+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		
		return result;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String searchName = request.getParameter("demo.name");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		AudCreditInfoQueryCondition qc = new AudCreditInfoQueryCondition();
		if (StringUtils.isNotEmpty(searchName)) {
		}
		page.setCondition(qc);

		Pager pager = new Pager();//this.audCreditInfoService.searchListPage(page);
		List<AudCreditInfoVO> list = (List<AudCreditInfoVO>) pager.getResultList();
		ListPageVO<AudCreditInfoVO> listPage = new ListPageVO<AudCreditInfoVO>(list, pager.getTotalCount());
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		try {
			this.audCreditInfoService.removeById(Long.valueOf(id));
			BaseLogUtils.info(logger, "removeById", "删除数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "removeById", "删除数据失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "removeById", "删除数据失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 根据 项目ID|流程实例ID 获取信审整体资料(包括显示信息和编辑信息)
	 * @param request
	 * @param response
	 * @return
	 * @throws BaseException
	 */
	@RequestMapping(value = "/getByProjectIdAndProIntId.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getByProjectIdAndProIntId(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String projectId = request.getParameter("projectId");
		String proIntId = request.getParameter("proIntId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(projectId)||StringUtils.isEmpty(proIntId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_AUD_PROINT_ID_NOT_EMPTY + SysLogConstant.LOG_AUD_PROJECT_ID_NOT_EMPTY);
			BaseLogUtils.error(logger, "getByProjectIdAndProIntId", "获取数据,缺少必要参数条件.projectId:"+projectId+",proIntId:"+proIntId, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			AuditCreditInfoQueryCondition qc = new AuditCreditInfoQueryCondition();
			qc.setProIntId(proIntId);
			qc.setProjectId(Long.valueOf(projectId));
			AudCreditInfoVO vo = this.audCreditInfoService.selectAudCreditInfoByQc(qc);
			BaseLogUtils.newLogger( "getByProjectIdAndProIntId.获取数据.projectId:"+projectId+",proIntId:"+proIntId).info();

			AuditStandingBookQueryCondition condition = new AuditStandingBookQueryCondition();
			condition.setProjectId(Long.valueOf(projectId));
			condition.setBookTypeCd(AuditConstans.AudTypeCdEnum.AUD_TYP_CD_PL.key());
			AudStandingBookListRequest listRequest = new AudStandingBookListRequest(condition,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
			ResponseData<List<AuditStandingBookDTO>> responseData = auditStandingBookService.searchList(listRequest);
			BaseLogUtils.newLogger( "selectAudStandingBookByQc.获取数据.projectId:"+projectId+",proIntId:"+proIntId
					+" response:{}",JSONObject.toJSONString(responseData)).info();
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getByProjectIdAndProIntId", "获取数据,数据不存在.projectId:"+projectId+",proIntId:"+proIntId, CurrentThreadContext.getCurrentUserName());
			}
			if (null != responseData && CollectionUtils.isNotEmpty(responseData.getData())) {
				AuditStandingBookDTO dto = responseData.getData().get(0);
				if (dto != null && StringUtils.isNotEmpty(dto.getAudRemainPro()) && StringUtils.isEmpty(vo.getAudRemainPro())) {
					vo.setAudRemainPro(dto.getAudRemainPro());
				}
			}

			result.setData(vo);
			BaseLogUtils.info(logger, "getByProjectIdAndProIntId", "获取数据.projectId:"+projectId+",proIntId:"+proIntId, CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getByProjectIdAndProIntId", "获取失败.[projectId:"+projectId+",proIntId:"+proIntId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getByProjectIdAndProIntId", "获取失败.[projectId:"+projectId+",proIntId:"+proIntId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		AudCreditInfoVO entity = null;
		try {
			entity = this.getRequestParamForAdd(request);
            //保存图谱风险信息
            result = this.saveMapRisk(request, result);
            if (Objects.equals(BaseConstant.IS_YESNO_NO, result.getSuccess())) {
                return result;
            }

			AuditCreditInfoDTO dto = new AuditCreditInfoDTO();
			BeanUtils.copyProperties(entity, dto);
			dto.setHouseCert(entity.getHouseCret());
			dto.setFareTypeCd(entity.getFareType());
			dto.setChargingTypeCd(entity.getChargingType());
			dto.setHandlingMode(entity.getHandingMode());
            //信审维护产品信息集合
            List<AudCarInfoVO> audCarInfoVOList = entity.getAudCarInfoVOList();
            if (CollectionUtils.isNotEmpty(audCarInfoVOList)) {
                List<AuditCarInfoDTO> auditCarInfoDTOS = new ArrayList<>();
                for (AudCarInfoVO audCarInfoVO : audCarInfoVOList) {
                    AuditCarInfoDTO auditCarInfoDTO = new AuditCarInfoDTO();
                    BeanUtils.copyProperties(audCarInfoVO, auditCarInfoDTO);
                    //peferPc->referPc，该字段vo与dto命名不一致，需手动赋值
                    auditCarInfoDTO.setReferPc(audCarInfoVO.getPeferPc());
                    auditCarInfoDTOS.add(auditCarInfoDTO);
                }
                dto.setAudCarInfoDTOList(auditCarInfoDTOS);
            }
			AddAudCreditInfoRequest addRequest = new AddAudCreditInfoRequest(dto, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
			ResponseData<Long> responseData = auditCreditInfoService.addAudCreditInfo(addRequest);
			if (!ResponseData.SUCCESS_CODE.equals(responseData.getCode())) {
				throw new BaseException(BaseExceptionConstant.DATABASE_0201_NAME, "新增数据失败");
			}
			result.setData(responseData.getData());

			this.modifyPrjPrdPayWayCd(request);
			BaseLogUtils.info(logger, "add", "新增数据.[id="+responseData.getData()+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		AudCreditInfoVO entity = null;
		try {
			entity = this.getRequestParamForModify(request);
            //保存图谱风险信息
            result = this.saveMapRisk(request, result);
            if (Objects.equals(BaseConstant.IS_YESNO_NO, result.getSuccess())) {
                return result;
            }
			entity.setId(Long.valueOf(id));

			AuditCreditInfoDTO auditCreditInfoDTO = new AuditCreditInfoDTO();
			BeanUtils.copyProperties(entity, auditCreditInfoDTO);
			auditCreditInfoDTO.setHouseCert(entity.getHouseCret());
			auditCreditInfoDTO.setFareTypeCd(entity.getFareType());
			auditCreditInfoDTO.setChargingTypeCd(entity.getChargingType());
			auditCreditInfoDTO.setHandlingMode(entity.getHandingMode());
			//信审维护产品信息集合
			List<AudCarInfoVO> audCarInfoVOList = entity.getAudCarInfoVOList();
			if (CollectionUtils.isNotEmpty(audCarInfoVOList)) {
				List<AuditCarInfoDTO> auditCarInfoDTOS = new ArrayList<>();
				for (AudCarInfoVO audCarInfoVO : audCarInfoVOList) {
					AuditCarInfoDTO auditCarInfoDTO = new AuditCarInfoDTO();
					BeanUtils.copyProperties(audCarInfoVO, auditCarInfoDTO);
					//peferPc->referPc，该字段vo与dto命名不一致，需手动赋值
					auditCarInfoDTO.setReferPc(audCarInfoVO.getPeferPc());
					auditCarInfoDTOS.add(auditCarInfoDTO);
				}
				auditCreditInfoDTO.setAudCarInfoDTOList(auditCarInfoDTOS);
			}
			ModifyAudCreditInfoRequest modifyRequest = new ModifyAudCreditInfoRequest(auditCreditInfoDTO, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
			ResponseData responseData = auditCreditInfoService.modifyAudCreditInfo(modifyRequest);
			if (!ResponseData.SUCCESS_CODE.equals(responseData.getCode())) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			this.modifyPrjPrdPayWayCd(request);
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	//保存图谱风险信息
	private DataResultVO saveMapRisk(HttpServletRequest request, DataResultVO result) throws BaseException{
	    try {
            String projectId = request.getParameter("projectId");//项目ID
            String mapRiskId = request.getParameter("mapRiskId");//图谱风险ID
            String isRisk = request.getParameter("isRisk");//图谱风险
            String riskTips = request.getParameter("riskTips");//风险提示
            String riskDetail = request.getParameter("riskDetail");//风险详细
            if (StringUtils.isEmpty(projectId)) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "项目ID不能为空");
            }
            if (StringUtils.isEmpty(isRisk)) {
                return new DataResultVO(BaseConstant.IS_YESNO_NO, "请选择图谱风险");
            }
            //图谱风险为 是 校验 风险提示 风险详细
            if (Objects.equals(new BaseConstant(), isRisk)) {
                if (StringUtils.isEmpty(riskTips)) {
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "请选择风险提示");
                }
                if (StringUtils.isEmpty(riskDetail)) {
                    return new DataResultVO(BaseConstant.IS_YESNO_NO, "请填写风险详细");
                }
            }
            PrjMapRiskVO prjMapRiskVO = new PrjMapRiskVO();
            prjMapRiskVO.setDataId(Long.valueOf(projectId));
            prjMapRiskVO.setMarkTypCd("PRJ");
            prjMapRiskVO.setIsRisk(Integer.parseInt(isRisk));
            prjMapRiskVO.setRiskTips(riskTips);
            prjMapRiskVO.setRiskDetail(riskDetail);
            if (StringUtils.isNotEmpty(mapRiskId)) {
                prjMapRiskVO.setId(Long.valueOf(mapRiskId));
                prjMapRiskVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
                prjMapRiskVO.setMdfTm(new Date());
                //修改
				PrjMapRiskDTO prjMapRiskDTO = new PrjMapRiskDTO();
				BeanUtils.copyProperties(prjMapRiskVO, prjMapRiskDTO);
				ModifyPrjMapRiskRequest modifyRequest = new ModifyPrjMapRiskRequest(prjMapRiskDTO);
				ResponseData responseData = projectMapRiskService.modifyPrjMapRisk(modifyRequest);
				if (!ResponseData.SUCCESS_CODE.equals(responseData.getCode())) {
					result.setSuccess(BaseConstant.IS_YESNO_NO);
					result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				}
            } else {
                //新增
                prjMapRiskVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                prjMapRiskVO.setCrtTm(new Date());
				PrjMapRiskDTO prjMapRiskDTO = new PrjMapRiskDTO();
				BeanUtils.copyProperties(prjMapRiskVO, prjMapRiskDTO);
				AddPrjMapRiskRequest addRequest = new AddPrjMapRiskRequest(prjMapRiskDTO);
				ResponseData responseData = projectMapRiskService.addPrjMapRisk(addRequest);
				if (!ResponseData.SUCCESS_CODE.equals(responseData.getCode())) {
					result.setSuccess(BaseConstant.IS_YESNO_NO);
					result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				}
            }
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "saveMapRisk", "保存图谱风险信息" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }
	
	/**
	 * 得到一条记录
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			AudCreditInfoVO vo = this.audCreditInfoService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initAudCreditInfo.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initAudCreditInfo(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String projectId = request.getParameter("projectId");
		String proIntId = request.getParameter("proIntId");
		AuditCreditInfoQueryCondition qc = new AuditCreditInfoQueryCondition();
		qc.setProIntId(proIntId);
		qc.setProjectId(Long.valueOf(projectId));
		AudCreditInfoVO vo = this.audCreditInfoService.selectAudCreditInfoByQc(qc);
		if(null != vo){
			String guaOpn = vo.getGuaOpn();
			String ugRlOpn = vo.getUgRlOpn();
			String houseCret = vo.getHouseCret();
			String wasteBook = vo.getWasteBook();
			JSONArray jsonArray = new JSONArray();
			JSONObject obj = null;
			int total = 0;
			if(StringUtils.isNotEmpty(guaOpn)){
				obj = new JSONObject();
				obj.put("field", "guaOpn");
				obj.put("fieldNm", "担保人");
				obj.put("fieldContent", guaOpn);
				jsonArray.add(obj);
				total++;
			}
			if(StringUtils.isNotEmpty(ugRlOpn)){
				obj = new JSONObject();
				obj.put("field", "ugRlOpn");
				obj.put("fieldNm", "联系人");
				obj.put("fieldContent", ugRlOpn);
				jsonArray.add(obj);
				total++;
			}
			if(StringUtils.isNotEmpty(houseCret)){
				obj = new JSONObject();
				obj.put("field", "houseCret");
				obj.put("fieldNm", "房产证明");
				obj.put("fieldContent", houseCret);
				jsonArray.add(obj);
				total++;
			}
			if(StringUtils.isNotEmpty(wasteBook)){
				obj = new JSONObject();
				obj.put("field", "wasteBook");
				obj.put("fieldNm", "流水");
				obj.put("fieldContent", wasteBook);
				jsonArray.add(obj);
				total++;
			}
			ListPageVO<Object> listPage = new ListPageVO<Object>(jsonArray,total);
			
			return listPage;
		}
		return null;
	}
	
	//********************私有方法********************//
	/**
	 * 获取参数信息
	 * @param request
	 * @return
	 * @throws BaseException
	 */
	private AudCreditInfoVO getRequestParam(HttpServletRequest request)throws BaseException{
		String projectId = request.getParameter("projectId");//项目ID
		String proIntId = request.getParameter("proIntId");//流程实例ID
		if(StringUtils.isEmpty(proIntId)||StringUtils.isEmpty(projectId)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "项目ID和流程实例ID不能为空.");
		}
		
		String actualAreaCd = request.getParameter("actualAreaCd");//实际区域?
		String productTypeCd = request.getParameter("prdTypCd");//产品类型
		String driverInfo = request.getParameter("driverInfo");//司机情况
		String startplace = request.getParameter("startplace");//出发地
		String destination = request.getParameter("destination");//目的地
		String tripGoods = request.getParameter("tripGoods");//去程货物
		String tripGoodsMainCd = request.getParameter("tripGoodsMainCd");//去程货物大类
		String tripGoodsSubCd = request.getParameter("tripGoodsSubCd");//去程货物小类
		String returnGoods = request.getParameter("returnGoods");//回程货物
		String returnGoodsMainCd = request.getParameter("returnGoodsMainCd");//回程货物大类
		String returnGoodsSubCd = request.getParameter("returnGoodsSubCd");//回程货物小类
		String mainGoodsCd = request.getParameter("mainGoodsCd");//主货物小类
		String weight = request.getParameter("weight");//承载重量
		String fareType = request.getParameter("fareType");//运费计算方式
		String returnNum = request.getParameter("returnNum");//往返趟数
		String settlementTypeCd = request.getParameter("settlementTypeCd");//结算方式
		String monthIncome = request.getParameter("monthIncome");//月净收入
		String monthRepayment = request.getParameter("monthRepayment");//月还款
		String distance = request.getParameter("distance");//运距
		String experience = request.getParameter("experience");//运营经验
		String useMainTypeCd = request.getParameter("useMainTypeCd");//车辆用途大类
		String useSubTypeCd = request.getParameter("useSubTypeCd");//车辆用途小类
		String passengersCd = request.getParameter("passengersCd");//载客数
		String chargingType = request.getParameter("chargingType");//计费方式
		String monthOutDays = request.getParameter("monthOutDays");//月出车天数
		String workTypeCd = request.getParameter("workTypeCd");//工作方式
		String professionCd = request.getParameter("professionCd");//职业
		String postCd = request.getParameter("postCd");//职务
		String workYeays = request.getParameter("workYeays");//从业年限
		String income = request.getParameter("income");//收入情况
		String secondPayResCd = request.getParameter("secondPayResCd");//第二还款来源
		String equipmentUse = request.getParameter("equipmentUse");//设备用途
		String ownLand = request.getParameter("ownLand");//自有耕地
		String contractLand = request.getParameter("contractLand");//承包耕地
		String contractYeays = request.getParameter("contractYeays");//承包年限
		String contractPrice = request.getParameter("contractPrice");//地租单价
		String growCrops = request.getParameter("growCrops");//种植作物
		String yield = request.getParameter("yield");//产量/斤
		String saleTime = request.getParameter("saleTime");//出售时间
		String salePrice = request.getParameter("salePrice");//出售单价/斤
		String grossIncome = request.getParameter("grossIncome");//种植毛收入
		String netIncome = request.getParameter("netIncome");//种植净收入
		String workArea = request.getParameter("workArea");//作业区域
		String workRange = request.getParameter("workRange");//作业范围
		String workSize = request.getParameter("workSize");//作业面积
		String workPrice = request.getParameter("workPrice");//作业单价
		String workIncome = request.getParameter("workIncome");//作业净收入
		String workTime = request.getParameter("workTime");//作业时间
		
		String selfTkDesc = request.getParameter("selfTkDesc");//自有车辆情况
		String profitCd = request.getParameter("profitCd");//收入方式
		String goods = request.getParameter("goods");//主运输货物
		String route = request.getParameter("route");//运营路线
		String goodsResCd = request.getParameter("goodsResCd");//货物来源
		String otherInfo = request.getParameter("otherInfo");//其他信息
		String qualificationOpn = request.getParameter("qualificationOpn");//资质评价
		String infomationOpn = request.getParameter("infomationOpn");//资料评价
		String schemeOpn = request.getParameter("schemeOpn");//方案评价
		String riskOpn = request.getParameter("riskOpn");//风险评价
		String offLionContract = request.getParameter("offLionContract");//线下合同资料
		String audRemainPro = request.getParameter("audRemainPro");//信审遗留问题（add by JL 20190819）
		String isNew = request.getParameter("isNew");//是否首次立项
		//贷前风险标记
		String preLoanRiskFlagCd = request.getParameter("preLoanRiskFlagCd");
		String processOpinionCd = request.getParameter("processOpinionCd");//流程审核意见
		String cstMgrLvlCd = request.getParameter("cstMgrLvlCd");//客户经理评级
		String localLiveTmCd = request.getParameter("localLiveTmCd");//本地生活年限
		String riskCtrlLvlCd = request.getParameter("riskCtrlLvlCd");//风控评级
		String firstPayResCd = request.getParameter("firstPayResCd");//首付款来源
		
		String localOrNo = request.getParameter("localOrNo");//本外地
		String industryTypeCd = request.getParameter("industryTypeCd");//所属行业
		String cstOpn = request.getParameter("cstOpn");//承租人
		String guaOpn_bus = request.getParameter("guaOpn");//担保人
		String ugRlOpn_bus = request.getParameter("ugRlOpn");//紧急联系人
		String houseCret_bus = request.getParameter("houseCret");//房产证明
//		String wasteBook = request.getParameter("wasteBook");//银行流水
		String companyDetail = request.getParameter("companyDetail");//公司详情
		String financialState = request.getParameter("financialState");//财务报表
		String tripartite = request.getParameter("tripartite");//人行征信及三方
		
		String isMeetPolicyCd = request.getParameter("isMeetPolicyCd");//是否符合政策
		String goodsDisp = request.getParameter("goodsDisp");//主运输货物描述
		
		String isSelfAnswer = request.getParameter("isSelfAnswer");//是否本人接听
		String identityCd = request.getParameter("identityCd");//身份与购车信息核实
		String repayTypCd = request.getParameter("repayTypCd");//还款方式
		String incomeSchema = request.getParameter("incomeSchema");//收入模式
		
		String pbcCreditInfo = request.getParameter("pbcCreditInfo");//人行征信
		String tripCreditInfo = request.getParameter("tripCreditInfo");//三方征信
		
		String ownCreditInfo = request.getParameter("ownCreditInfo");//个人征信
		
		String highEasonCharterdBus = request.getParameter("highEasonCharterdBus");//旺季包车费
		String peakEasonCharterdBus = request.getParameter("peakEasonCharterdBus");//淡季包车费
		String otherFeePct = request.getParameter("otherFeePct");//其他费用占比
		
		//生成基础台账用
		String taskDefKey = request.getParameter("taskDefKey");//节点KEY
		String taskNm = request.getParameter("taskNm");//节点名称
		String insCode = request.getParameter("insCode");
		if (PrjBscInfoConstant.PRJ_INS_CODE_CCBANK.equals(insCode)) {
			if (StringUtils.isEmpty(goods)) {
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "主运输货物不能为空");
			}
			if (StringUtils.isEmpty(route)) {
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "运营路线不能为空");
			}
		}

		// 问题记录
		String problemRecordCd = request.getParameter("problemRecordCd");
		//是否呈报
		String submitCd = request.getParameter("submitCd");
		//问题描述
		String problemDesc = request.getParameter("problemDesc");
		//业务实质
		String bussEssenceCd = request.getParameter("bussEssenceCd");
		String bussEssence = request.getParameter("bussEssence");
		//经验
		String experienceCd = request.getParameter("experienceCd");
		//货源
		String goodsSourceCd = request.getParameter("goodsSourceCd");
		//拆单/顶名嫌疑
		String suspicionCd = request.getParameter("suspicionCd");
		//还款能力
		String repaymentCapacityCd = request.getParameter("repaymentCapacityCd");
		//配合度
		String complianceCd = request.getParameter("complianceCd");

		List<AudCarInfoVO> audCarInfoVOList = new ArrayList<AudCarInfoVO>();//信审扩展车辆信息List
		//车抵贷列表信息
		String odrPrdInfo = request.getParameter("odrPrdInfo");
		if(StringUtils.isNotBlank(odrPrdInfo)){
			List<OdrPrdBscInfoVO> odrPrdBscInfoVOList = JSON.parseArray(odrPrdInfo, OdrPrdBscInfoVO.class);
			if(CollectionUtils.isNotEmpty(odrPrdBscInfoVOList)){
				for (OdrPrdBscInfoVO odrPrdBscInfoVO : odrPrdBscInfoVOList) {
					AudCarInfoVO audCarInfoVO = odrPrdBscInfoVO.getAudCarInfoVO();
					audCarInfoVO.setPrjPrdId(odrPrdBscInfoVO.getId());
					audCarInfoVOList.add(audCarInfoVO);
				}
			}
		}
		//卡车列表信息
		String truckInfo = request.getParameter("truckInfo");
		if(StringUtils.isNotBlank(truckInfo)){
			List<PrjPrdBscInfoVO> prjPrdBscInfoVOList = JSON.parseArray(truckInfo, PrjPrdBscInfoVO.class);
			if(CollectionUtils.isNotEmpty(prjPrdBscInfoVOList)){
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prjPrdBscInfoVOList) {
					AudCarInfoVO audCarInfoVO = prjPrdBscInfoVO.getAudCarInfoVO();
					audCarInfoVO.setPrjPrdId(prjPrdBscInfoVO.getId());
					audCarInfoVOList.add(audCarInfoVO);
				}
			}
		}
		//新能源客车列表信息
		String xnyBusInfo = request.getParameter("xnyBusInfo");
		if(StringUtils.isNotBlank(xnyBusInfo)){
			List<PrjPrdBscInfoVO> prjPrdBscInfoVOList = JSON.parseArray(xnyBusInfo, PrjPrdBscInfoVO.class);
			if(CollectionUtils.isNotEmpty(prjPrdBscInfoVOList)){
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prjPrdBscInfoVOList) {
					AudCarInfoVO audCarInfoVO = prjPrdBscInfoVO.getAudCarInfoVO();
					audCarInfoVO.setPrjPrdId(prjPrdBscInfoVO.getId());
					audCarInfoVOList.add(audCarInfoVO);
				}
			}
		}
		//卡车列表信息
		String xnyTkInfo = request.getParameter("xnyTkInfo");
		if(StringUtils.isNotBlank(xnyTkInfo)){
			List<PrjPrdBscInfoVO> prjPrdBscInfoVOList = JSON.parseArray(xnyTkInfo, PrjPrdBscInfoVO.class);
			if(CollectionUtils.isNotEmpty(prjPrdBscInfoVOList)){
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prjPrdBscInfoVOList) {
					AudCarInfoVO audCarInfoVO = prjPrdBscInfoVO.getAudCarInfoVO();
					audCarInfoVO.setPrjPrdId(prjPrdBscInfoVO.getId());
					audCarInfoVOList.add(audCarInfoVO);
				}
			}
		}
		//卡车类客车 列表信息
		String tkBusInfo = request.getParameter("tkBusInfo");
		if(StringUtils.isNotBlank(tkBusInfo)){
			List<PrjPrdBscInfoVO> prjPrdBscInfoVOList = JSON.parseArray(tkBusInfo, PrjPrdBscInfoVO.class);
			if(CollectionUtils.isNotEmpty(prjPrdBscInfoVOList)){
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prjPrdBscInfoVOList) {
					AudCarInfoVO audCarInfoVO = prjPrdBscInfoVO.getAudCarInfoVO();
					audCarInfoVO.setPrjPrdId(prjPrdBscInfoVO.getId());
					audCarInfoVOList.add(audCarInfoVO);
				}
			}
		}
		//乘用车列表信息
		String carInfo = request.getParameter("carInfo");
		if(StringUtils.isNotBlank(carInfo)){
			List<PrjPrdBscInfoVO> prjPrdBscInfoVOList = JSON.parseArray(carInfo, PrjPrdBscInfoVO.class);
			if(CollectionUtils.isNotEmpty(prjPrdBscInfoVOList)){
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prjPrdBscInfoVOList) {
					AudCarInfoVO audCarInfoVO = prjPrdBscInfoVO.getAudCarInfoVO();
					/*String carLevelCd = audCarInfoVO.getCarLevelCd();
					if(StringUtils.isEmpty(carLevelCd)){
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "车辆级别不能为空");
					}*/
					audCarInfoVO.setPrjPrdId(prjPrdBscInfoVO.getId());
					if(null!=audCarInfoVO && null!=audCarInfoVO.getGuidePcDouble()){
						audCarInfoVO.setGuidePc(DecimalUtils.convertYuanToFen(audCarInfoVO.getGuidePcDouble()));
					}
					if(null!=audCarInfoVO && null!=audCarInfoVO.getPeferPcDouble()){
						audCarInfoVO.setPeferPc(DecimalUtils.convertYuanToFen(audCarInfoVO.getPeferPcDouble()));
					}
					
					audCarInfoVOList.add(audCarInfoVO);
				}
			}
		}
		//专车列表信息  专车目前没有需要信审维护的产品信息
		String busInfo = request.getParameter("busInfo");
		if(StringUtils.isNotBlank(busInfo)){
			List<PrjPrdBscInfoVO> prjPrdBscInfoVOList = JSON.parseArray(busInfo, PrjPrdBscInfoVO.class);
			if(CollectionUtils.isNotEmpty(prjPrdBscInfoVOList)){
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prjPrdBscInfoVOList) {
					AudCarInfoVO audCarInfoVO = prjPrdBscInfoVO.getAudCarInfoVO();
					audCarInfoVO.setPrjPrdId(prjPrdBscInfoVO.getId());
					audCarInfoVOList.add(audCarInfoVO);
				}
			}
		}
		//农机列表信息
		String farmInfo = request.getParameter("farmInfo");
		if(StringUtils.isNotBlank(farmInfo)){
			List<PrjPrdBscInfoVO> prjPrdBscInfoVOList = JSON.parseArray(farmInfo, PrjPrdBscInfoVO.class);
			if(CollectionUtils.isNotEmpty(prjPrdBscInfoVOList)){
				for (PrjPrdBscInfoVO prjPrdBscInfoVO : prjPrdBscInfoVOList) {
					AudCarInfoVO audCarInfoVO = prjPrdBscInfoVO.getAudCarInfoVO();
					audCarInfoVO.setPrjPrdId(prjPrdBscInfoVO.getId());
					audCarInfoVOList.add(audCarInfoVO);
				}
			}
		}
		//设置信审整体资料车辆信息  项目产品ID
		/*if(CollectionUtils.isNotEmpty(audCarInfoVOList)){
			for (AudCarInfoVO audCarInfoVO : audCarInfoVOList) {
				audCarInfoVO.setPrjPrdId(audCarInfoVO.getId());
				audCarInfoVO.setId(null);
			}
		}*/

		AudCreditInfoVO audCreditInfoVO = new AudCreditInfoVO();
		audCreditInfoVO.setAudCarInfoVOList(audCarInfoVOList);
		
		if(StringUtils.isNotEmpty(projectId)){
			audCreditInfoVO.setProjectId(Long.valueOf(projectId));
		}
		String circuitType = request.getParameter("circuitType");
		String cargoWeigth = request.getParameter("cargoWeigth");
		String cargoVomule = request.getParameter("cargoVomule");
		String handingMode = request.getParameter("handingMode");
		String circuitEfficiency = request.getParameter("circuitEfficiency");
		String Fare = request.getParameter("fare");
		 String visitStatus = "1";
		audCreditInfoVO.setProIntId(proIntId);
		audCreditInfoVO.setActualAreaCd(actualAreaCd);
		audCreditInfoVO.setProductTypeCd(productTypeCd);
		audCreditInfoVO.setDriverInfo(driverInfo);
		audCreditInfoVO.setStartplace(startplace);
		audCreditInfoVO.setDestination(destination);
		audCreditInfoVO.setTripGoods(tripGoods);
		audCreditInfoVO.setTripGoodsMainCd(tripGoodsMainCd);
		audCreditInfoVO.setTripGoodsSubCd(tripGoodsSubCd);
		audCreditInfoVO.setReturnGoods(returnGoods);
		audCreditInfoVO.setReturnGoodsMainCd(returnGoodsMainCd);
		audCreditInfoVO.setReturnGoodsSubCd(returnGoodsSubCd);
		audCreditInfoVO.setMainGoodsCd(mainGoodsCd);
		audCreditInfoVO.setWeight(weight);
		audCreditInfoVO.setFareType(fareType);
		audCreditInfoVO.setVisitStatus(visitStatus);
		if(StringUtils.isNotEmpty(visitStatus)){
			audCreditInfoVO.setVisitStatus(visitStatus);//已回访
		}
		if(StringUtils.isNotEmpty(circuitType)){
			audCreditInfoVO.setCircuitType(circuitType);
		}
		if(StringUtils.isNotEmpty(cargoWeigth)){
			audCreditInfoVO.setCargoWeigth(cargoWeigth);
		}
		if(StringUtils.isNotEmpty(cargoVomule)){
			audCreditInfoVO.setCargoVomule(cargoVomule);
		}
		if(StringUtils.isNotEmpty(handingMode)){
			audCreditInfoVO.setHandingMode(handingMode);
		}
		if(StringUtils.isNotEmpty(circuitEfficiency)){
			audCreditInfoVO.setCircuitEfficiency(circuitEfficiency);
		}
		if(StringUtils.isNotEmpty(Fare)){
			audCreditInfoVO.setFare(Fare);
		}
		
		if(StringUtils.isNotEmpty(returnNum)){
			audCreditInfoVO.setReturnNum(Long.valueOf(returnNum));
		}
		audCreditInfoVO.setSettlementTypeCd(settlementTypeCd);
		if(StringUtils.isNotEmpty(monthIncome)){
			audCreditInfoVO.setMonthIncome(DecimalUtils.convertYuanToFen(Double.valueOf(monthIncome)));
		}
		if(StringUtils.isNotEmpty(monthRepayment)){
			audCreditInfoVO.setMonthRepayment(DecimalUtils.convertYuanToFen(Double.valueOf(monthRepayment)));
		}
		if(StringUtils.isNotEmpty(distance)){
			audCreditInfoVO.setDistance(Long.valueOf(distance));
		}
		audCreditInfoVO.setExperience(experience);
		audCreditInfoVO.setUseMainTypeCd(useMainTypeCd);
		audCreditInfoVO.setUseSubTypeCd(useSubTypeCd);
		audCreditInfoVO.setPassengersCd(passengersCd);
		audCreditInfoVO.setChargingType(chargingType);
		audCreditInfoVO.setMonthOutDays(monthOutDays);
		audCreditInfoVO.setWorkTypeCd(workTypeCd);
		audCreditInfoVO.setIndustryTypeCd(industryTypeCd);
		audCreditInfoVO.setProfessionCd(professionCd);
		audCreditInfoVO.setPostCd(postCd);
		audCreditInfoVO.setWorkYeays(workYeays);
		audCreditInfoVO.setIncome(income);
		audCreditInfoVO.setSecondPayResCd(secondPayResCd);
		audCreditInfoVO.setEquipmentUse(equipmentUse);
		audCreditInfoVO.setOwnLand(ownLand);
		audCreditInfoVO.setContractLand(contractLand);
		if(StringUtils.isNotEmpty(contractYeays)){
			audCreditInfoVO.setContractYeays(Long.valueOf(contractYeays));
		}
		if(StringUtils.isNotEmpty(contractPrice)){
			audCreditInfoVO.setContractPrice(DecimalUtils.convertYuanToFen(Double.valueOf(contractPrice)));
		}
		audCreditInfoVO.setGrowCrops(growCrops);
		if(StringUtils.isNotEmpty(yield)){
			audCreditInfoVO.setYield(Long.valueOf(yield));
		}
		if(StringUtils.isNotEmpty(saleTime)){
			audCreditInfoVO.setSaleTime(DateUtils.formatStringToDate(saleTime, DateUtils.YYYY_MM_DD));
		}
		if(StringUtils.isNotEmpty(salePrice)){
			audCreditInfoVO.setSalePrice(DecimalUtils.convertYuanToFen(Double.valueOf(salePrice)));
		}
		if(StringUtils.isNotEmpty(grossIncome)){
			audCreditInfoVO.setGrossIncome(DecimalUtils.convertYuanToFen(Double.valueOf(grossIncome)));
		}
		if(StringUtils.isNotEmpty(netIncome)){
			audCreditInfoVO.setNetIncome(DecimalUtils.convertYuanToFen(Double.valueOf(netIncome)));
		}
		audCreditInfoVO.setWorkArea(workArea);
		audCreditInfoVO.setWorkRange(workRange);
		if(StringUtils.isNotEmpty(workSize)){
			audCreditInfoVO.setWorkSize(Long.valueOf(workSize));
		}
		if(StringUtils.isNotEmpty(workPrice)){
			audCreditInfoVO.setWorkPrice(DecimalUtils.convertYuanToFen(Double.valueOf(workPrice)));
		}
		if(StringUtils.isNotEmpty(workIncome)){
			audCreditInfoVO.setWorkIncome(DecimalUtils.convertYuanToFen(Double.valueOf(workIncome)));
		}
		if(StringUtils.isNotEmpty(workTime)){
			audCreditInfoVO.setWorkTime(DateUtils.formatStringToDate(workTime, DateUtils.YYYY_MM_DD));
		}
		
		audCreditInfoVO.setSelfTkDesc(selfTkDesc);
		audCreditInfoVO.setProfitCd(profitCd);
		audCreditInfoVO.setGoods(goods);
		audCreditInfoVO.setRoute(route);
		audCreditInfoVO.setGoodsResCd(goodsResCd);
		audCreditInfoVO.setOtherInfo(otherInfo);
		audCreditInfoVO.setQualificationOpn(qualificationOpn);
		audCreditInfoVO.setInfomationOpn(infomationOpn);
		audCreditInfoVO.setSchemeOpn(schemeOpn);
		audCreditInfoVO.setRiskOpn(riskOpn);
		audCreditInfoVO.setOffLionContract(offLionContract);
		audCreditInfoVO.setAudRemainPro(audRemainPro);//信审遗留问题（add by JL 20190819）
		if(StringUtils.isNotEmpty(isNew)){
			audCreditInfoVO.setIsNew(Integer.valueOf(isNew));
		}
		if(StringUtils.isNotEmpty(preLoanRiskFlagCd)){
			audCreditInfoVO.setPreLoanRiskFlagCd(Integer.valueOf(preLoanRiskFlagCd));
		}
		audCreditInfoVO.setProcessOpinionCd(processOpinionCd);
		audCreditInfoVO.setCstMgrLvlCd(cstMgrLvlCd);
		audCreditInfoVO.setLocalLiveTmCd(localLiveTmCd);
		audCreditInfoVO.setRiskCtrlLvlCd(riskCtrlLvlCd);
		audCreditInfoVO.setFirstPayResCd(firstPayResCd);
		
		audCreditInfoVO.setLocalOrNo(localOrNo);
		audCreditInfoVO.setCstOpn(cstOpn);
		audCreditInfoVO.setUgRlOpn(ugRlOpn_bus);
		audCreditInfoVO.setGuaOpn(guaOpn_bus);
		audCreditInfoVO.setHouseCret(houseCret_bus);
		audCreditInfoVO.setWasteBook("");
		audCreditInfoVO.setCompanyDetail(companyDetail);
		audCreditInfoVO.setFinancialState(financialState);
		audCreditInfoVO.setTripartite(tripartite);
		audCreditInfoVO.setIsMeetPolicyCd(isMeetPolicyCd);
		audCreditInfoVO.setGoodsDisp(goodsDisp);
		if(StringUtils.isNotEmpty(isSelfAnswer)){
			audCreditInfoVO.setIsSelfAnswer(Integer.valueOf(isSelfAnswer));
		}
		audCreditInfoVO.setIdentityCd(identityCd);
		audCreditInfoVO.setRepayTypCd(repayTypCd);
		audCreditInfoVO.setIncomeSchema(incomeSchema);
		audCreditInfoVO.setPbcCreditInfo(pbcCreditInfo);
		audCreditInfoVO.setTripCreditInfo(tripCreditInfo);
		audCreditInfoVO.setOwnCreditInfo(ownCreditInfo);
		if(StringUtils.isNotEmpty(highEasonCharterdBus)){
			audCreditInfoVO.setHighEasonCharterdBus(DecimalUtils.convertYuanToFen(Double.valueOf(highEasonCharterdBus)));
		}
		if(StringUtils.isNotEmpty(peakEasonCharterdBus)){
			audCreditInfoVO.setPeakEasonCharterdBus(DecimalUtils.convertYuanToFen(Double.valueOf(peakEasonCharterdBus)));
		}
		if(StringUtils.isNotEmpty(otherFeePct)){
			audCreditInfoVO.setOtherFeePct(Double.valueOf(otherFeePct));
		}

		audCreditInfoVO.setTaskDefKey(taskDefKey);
		audCreditInfoVO.setTaskNm(taskNm);

		if (StringUtils.isNotEmpty(problemRecordCd)) {
			audCreditInfoVO.setProblemRecordCd(problemRecordCd);
		}
		if (StringUtils.isNotEmpty(submitCd)) {
			audCreditInfoVO.setSubmitCd(submitCd);
		}
		if (StringUtils.isNotEmpty(bussEssenceCd)) {
			audCreditInfoVO.setBussEssenceCd(bussEssenceCd);
		}
		audCreditInfoVO.setProblemDesc(problemDesc);
		audCreditInfoVO.setBussEssence(bussEssence);

		if (StringUtils.isNotEmpty(experienceCd)) {
			audCreditInfoVO.setExperienceCd(experienceCd);
		}
		if (StringUtils.isNotEmpty(goodsSourceCd)) {
			audCreditInfoVO.setGoodsSourceCd(goodsSourceCd);
		}
		if (StringUtils.isNotEmpty(suspicionCd)) {
			audCreditInfoVO.setSuspicionCd(suspicionCd);
		}
		if (StringUtils.isNotEmpty(repaymentCapacityCd)) {
			audCreditInfoVO.setRepaymentCapacityCd(repaymentCapacityCd);
		}
		if (StringUtils.isNotEmpty(complianceCd)) {
			audCreditInfoVO.setComplianceCd(complianceCd);
		}
		
		String auditGridJSON = request.getParameter("auditGridJSON");
		if(StringUtils.isNotEmpty(auditGridJSON)){
			JSONArray json = JSONArray.fromObject(auditGridJSON);
			int guaOpn = 0;
			int ugRlOpn = 0;
			int houseCret = 0;
			int wasteBook = 0;
			if(json.size()>0){
				  for(int i=0;i<json.size();i++){
				    net.sf.json.JSONObject job = json.getJSONObject(i);  // 遍历 jsonarray 数组，把每一个对象转成 json 对象
				    String field = (String) job.get("field");
				    String fieldContent = (String) job.get("fieldContent");
				    if("guaOpn".equals(field)){
				    	audCreditInfoVO.setGuaOpn(fieldContent);
				    	guaOpn++;
				    }else if("ugRlOpn".equals(field)){
				    	audCreditInfoVO.setUgRlOpn(fieldContent);
				    	ugRlOpn++;
				    }else if("houseCret".equals(field)){
				    	audCreditInfoVO.setHouseCret(fieldContent);
				    	houseCret++;
				    }else if("wasteBook".equals(field)){
				    	audCreditInfoVO.setWasteBook(fieldContent);
				    	wasteBook++;
				    }
				  }
			}
			if(guaOpn>1 || ugRlOpn>1 || houseCret>1 || wasteBook>1){
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "其他信息中同一类别不能重复添加.");
			}
		}
		
		return audCreditInfoVO;
	}
	
	/**
	 * 获取请求参数(新增)
	 * @param request 请求
	 * @return 
	 */
	private AudCreditInfoVO getRequestParamForAdd(HttpServletRequest request)throws BaseException{
		AudCreditInfoVO audCreditInfoVO = this.getRequestParam(request);
		audCreditInfoVO.setCrtTm(new Date());
		audCreditInfoVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		List<AudCarInfoVO> audCarInfoVOList = audCreditInfoVO.getAudCarInfoVOList();
		if(CollectionUtils.isNotEmpty(audCarInfoVOList)){
			for (AudCarInfoVO audCarInfoVO : audCarInfoVOList) {
				audCarInfoVO.setCrtTm(new Date());
				audCarInfoVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			}
		}
		return audCreditInfoVO;
	}
	
	/**
	 * 获取请求参数(修改)
	 * @param request 请求
	 * @return 
	 */
	private AudCreditInfoVO getRequestParamForModify(HttpServletRequest request)throws BaseException{
		AudCreditInfoVO audCreditInfoVO = this.getRequestParam(request);
		audCreditInfoVO.setMdfTm(new Date());
		audCreditInfoVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		List<AudCarInfoVO> audCarInfoVOList = audCreditInfoVO.getAudCarInfoVOList();
		if(CollectionUtils.isNotEmpty(audCarInfoVOList)){
			for (AudCarInfoVO audCarInfoVO : audCarInfoVOList) {
				audCarInfoVO.setMdfTm(new Date());
				audCarInfoVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			}
		}
		return audCreditInfoVO;
	}

	private void modifyPrjPrdPayWayCd(HttpServletRequest request)throws BaseException{
		try{
			String isSplMfr = request.getParameter("isSplMfr");
			if(!"1".equals(isSplMfr)){
				return;//非厂商业务无需修改厂商放款方式
			}
			String truckInfo = request.getParameter("truckInfo");
			if(StringUtils.isNotBlank(truckInfo)) {
				List<PrjPrdBscInfoVO> prjPrdBscInfoVOList = JSON.parseArray(truckInfo, PrjPrdBscInfoVO.class);
				if (CollectionUtils.isNotEmpty(prjPrdBscInfoVOList)) {
					PrjPrdBscInfoVO prjPrdBscInfoVOmdf = null;
					for (PrjPrdBscInfoVO prjPrdBscInfoVO : prjPrdBscInfoVOList){
						if(StringUtils.isEmpty(prjPrdBscInfoVO.getPayWayCd())){
							throw new BaseException("厂商放款方式不能为空!");
						}
						prjPrdBscInfoVOmdf = new PrjPrdBscInfoVO();
						prjPrdBscInfoVOmdf.setId(prjPrdBscInfoVO.getId());
						prjPrdBscInfoVOmdf.setPayWayCd(prjPrdBscInfoVO.getPayWayCd());
						this.prjPrdBscInfoService.modify(prjPrdBscInfoVOmdf);
					}
				}
			}
		}catch (BaseException e){
			throw e;
		}catch (Exception e){
			BaseLogUtils.info(logger,"modifyPrjPrdPayWayCd","修改产品付款方式异常!",e);
			throw new BaseException("修改产品付款方式异常");
		}
	}
	
	/**
	 * 根据 项目ID 获取信审整体资料
	 * @param request
	 * @param response
	 * @return
	 * @throws BaseException
	 */
	@RequestMapping(value = "/getAudCreditInfoByPrjId.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getAudCreditInfoByPrjId(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String projectId = request.getParameter("projectId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(projectId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_AUD_PROINT_ID_NOT_EMPTY + SysLogConstant.LOG_AUD_PROJECT_ID_NOT_EMPTY);
			BaseLogUtils.error(logger, "getAudCreditInfoByPrjId", "获取数据,缺少必要参数条件.projectId:"+projectId, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			AuditCreditInfoQueryCondition qc = new AuditCreditInfoQueryCondition();
			qc.setProjectId(Long.valueOf(projectId)); //项目ID
			AudCreditInfoVO vo = this.audCreditInfoService.getAudCreditInfoByQc(qc);
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getAudCreditInfoByPrjId", "获取数据,数据不存在.projectId:"+projectId, CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getAudCreditInfoByPrjId", "获取数据.projectId:"+projectId, CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getAudCreditInfoByPrjId", "获取失败.[projectId:"+projectId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getAudCreditInfoByPrjId", "获取失败.[projectId:"+projectId+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 修改信审整体资料-信审遗留问题
	 * @author JL 20190819
	 */
	@RequestMapping(value = "/modifyAudCreditInfo.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modifyAudCreditInfo(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		String audRemainPro =  request.getParameter("audRemainPro"); //信审遗留问题
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modifyAudCreditInfo", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		AudCreditInfoVO entity = new AudCreditInfoVO();
		try {
			entity.setAudRemainPro(audRemainPro);
			entity.setMdfTm(new Date());
			entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			entity.setId(Long.valueOf(id));

			AuditCreditInfoDTO auditCreditInfoDTO = new AuditCreditInfoDTO();
			BeanUtils.copyProperties(entity, auditCreditInfoDTO);
			auditCreditInfoDTO.setHouseCert(entity.getHouseCret());
			auditCreditInfoDTO.setFareTypeCd(entity.getFareType());
			auditCreditInfoDTO.setChargingTypeCd(entity.getChargingType());
			auditCreditInfoDTO.setHandlingMode(entity.getHandingMode());
			ModifyAudCreditInfoRequest modifyRequest = new ModifyAudCreditInfoRequest(auditCreditInfoDTO, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
			ResponseData responseData = auditCreditInfoService.modifyAudCreditInfo(modifyRequest);
			if (!ResponseData.SUCCESS_CODE.equals(responseData.getCode())) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.info(logger, "modifyAudCreditInfo", "修改失败1.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "modifyAudCreditInfo", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modifyAudCreditInfo", "修改失败2.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modifyAudCreditInfo", "修改失败3.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
}

